#include "Tiled.h"


Tiled::Tiled()
{

}

Tiled::Tiled(int index, int id, float posX, float posY)
{	
	m_posX = posX;
	m_posY = posY;
	m_height = TILED_HEIGTH;
	m_width = TILED_WIDTH;
	m_id = id;
	m_index = index;
	init();	
}

Tiled::~Tiled()
{

}

void Tiled::update(float time)
{

}

void Tiled::draw()
{
	int rows = m_sprite->getWidthTiled() / TILED_WIDTH;
	int left = (m_id % rows) * TILED_WIDTH;
	int top = (m_id / rows)  * TILED_HEIGTH;
	int right = left + TILED_WIDTH;
	int bot = top + TILED_HEIGTH;
	m_sprite->setRECT(left,top,right,bot);

	D3DXVECTOR2 pos = m_camera->getPointTransform(m_posX, m_posY);
	m_sprite->setPostion(pos);

	m_sprite->draw(m_spriteHandler);
}

void Tiled::init()
{
	m_spriteHandler = ResourceManager::getInstance()->m_spriteHandler;
	m_camera = ResourceManager::getInstance()->m_camera;
	m_level = ResourceManager::getInstance()->m_levelMap;

	// load sprite
	switch (m_level)
	{
	case 1:
		m_sprite = ResourceManager::getInstance()->play_bg1;
		break;
	case 2:
		m_sprite = ResourceManager::getInstance()->play_bg2;
		break;
	case 3:
		break;
	default:
		break;
	}
}


